package com.rankeiot.core.util.castor;

import java.math.BigDecimal;

@SuppressWarnings("AlibabaConstantFieldShouldBeUpperCase")
public class BigDecimalCastor implements Castor<BigDecimal> {
    public static final BigDecimalCastor instance=new BigDecimalCastor();
    @Override
    public BigDecimal cast(Object value) {
        if (value == null) {
            return null;
        } else if (value instanceof BigDecimal) {
            return (BigDecimal) value;
        } else if (value instanceof Double) {
            return new BigDecimal((Double) value);
        } else if (value instanceof Integer) {
            return new BigDecimal((Integer) value);
        } else if (value instanceof Long) {
            return new BigDecimal((Long) value);
        } else if (value instanceof Float) {
            return new BigDecimal((Float) value);
        } else {
            return new BigDecimal(value.toString());
        }
    }
}
